<?php

declare(strict_types=1);
/**
 * @copyright 深圳市易果网络科技有限公司
 * @version 1.0.0
 * @link https://dayiguo.com
 */

namespace App\Controller\business\v2;

use App\Constants\Constants;
use App\Dao\BusinessIndustryDao;
use App\Middleware\User\UserMiddleware;

use App\Request\Business\Business\ChangeJoiningWayRequest;
use App\Request\Business\Business\v2\BusinessCertRequest;

use App\Controller\Business\Controller;

use App\Service\Business\v2\BusinessService;
use Hyperf\Di\Annotation\Inject;
use Hyperf\HttpServer\Annotation\AutoController;
use Hyperf\HttpServer\Annotation\Middleware;

/**
 * 商家控制器
 *
 * @AutoController()
 * @Middleware(UserMiddleware::class)
 * @author 张昊(2396675557@qq.com)
 * @package App\Controller\business
 */
class BusinessController extends Controller
{

    /**
     * @Inject
     * @var BusinessService
     */
    public $business_service;

    /**
     * 行业类别DAO
     *
     * @Inject
     * @var BusinessIndustryDao
     */
    public $business_industry_dao;

    /**
     * 获取商家加盟方式
     */
    public function getJoiningWay()
    {
        $result = $this->business_service->getJoiningWay();

        $this->success($result);
    }

    /**
     * 获取商家信息
     */
    public function getInfo()
    {
        $result = $this->business_service->getInfo();

        $this->success($result);
    }

    /**
     * 获取商家审核结果
     */
    public function getBusinessAuditResult()
    {
        $result = $this->business_service->dao->first(['user_id' => uid()],['id','user_id','status','audit_result']);


        if( !empty($result) ) {
            if( $result['status'] == '3' ) {
                $return = [
                    'result' => $result['audit_result'],
                    'status' => $result['status']
                ];
            }
            if( $result['status'] == '2' ) {
                $return = [
                    'result' => "待审核",
                    'status' => $result['status']
                ];
            }
            if( $result['status'] == '1' ) {
                $return = [
                    'result' => "通过",
                    'status' => $result['status']
                ];
            }
        } else {
            $return = [
                'result' => "未认证",
                'status' => 0
            ];
        }


        $result ?$this->success($result):$this->error();
    }


    /**
     * 商家认证
     * @param BusinessCertRequest $request
     */
    public function add(BusinessCertRequest $request)
    {
        $params = $request->all();

        $result = $this->business_service->add($params);

        $this->success($result);
    }

    /**
     * 获取行业类别
     */
    public function getIndustryInfo()
    {
        $list = $this->business_industry_dao->getBusinessIndustryInfo();

        $this->success($list);
    }

    /**
     * 选择入驻方式
     * @param ChangeJoiningWayRequest $request
     */
    public function setEntryMode(ChangeJoiningWayRequest $request)
    {
        $params = $request->all();

        $result = $this->business_service->setEntryMode($params);

        $this->success($result);
    }

}